//
//  ReadViewController.m
//  LO_MUSIC
//
//  Created by 向祖华 on 16/2/24.
//  Copyright © 2016年 杨少锋. All rights reserved.
//

#import "ReadViewController.h"
#define GETURL @"http://api2.pianke.me/read/columns"
#define POSTURL @"http://api2.pianke.me/ting/radio"
/*
@{@"client":@"1",@"deviceid":@"63A94D37-33F9-40FF-9EBB-481182338873",@"auth":@"",@"version":@"3.0.2"}
 */
@interface ReadViewController ()

@end

@implementation ReadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    //GET

    
    //POST
    
    
    
    
    
}

-(void)post{

    NSURLSession * session = [NSURLSession sharedSession];
    //字符串转utf - 8(防止有汉字)
    NSCharacterSet * set = [NSCharacterSet characterSetWithCharactersInString:POSTURL];
    NSString * urlString = [POSTURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    //创建请求对象
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //设置request
    [request setHTTPMethod:@"POST"];
    //请求体
    NSString * bodyStr = @"client=1&deviceid=63A94D37-33F9-40FF-9EBB-481182338873=&auth=&version=3.0.2";
    NSData * data = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    NSURLSessionTask * task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        id result = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingAllowFragments) error:nil];
        NSLog(@"%@",result);
    }];
    
    [task resume];
}
-(void)get{
    //get
    NSURLSession * session = [NSURLSession sharedSession];
    //字符串转utf - 8
    NSCharacterSet * set = [NSCharacterSet characterSetWithCharactersInString:GETURL];
    NSString * urlString = [GETURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    //创建请求对象
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //设置request
    [request setHTTPMethod:@"GET"];
    
    //    [request setHTTPBody:nil];
    NSURLSessionTask * task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        id result = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingAllowFragments) error:nil];
        NSLog(@"%@",result);
    }];
    
    [task resume];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
